﻿<Window x:Class="ShumaDaf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="ShumaDaf" 
        xmlns:my="clr-namespace:ShumaDaf" mc:Ignorable="d" 
        xmlns:Converters="clr-namespace:Sherbanov.Converters"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="390" d:DesignWidth="756" 
         Closing="Window_Closing" Icon="/ShumaDaf;component/Images/003.jpg" Loaded="Window_Loaded">
    
    <Window.Resources>
        
        <my:RuntimeConverter x:Key="runtime" />
        <my:Int2ColorConverter x:Key="colorConv" />
        <my:StatusColorConv x:Key="StatusColorConv" />
        <Converters:b2gbConverter x:Key="b2g" />
        <my:Int2CheckConverter x:Key="int2check" />
        <my:s2i x:Key="s2i"></my:s2i>
        
        <my:DesireConverter x:Key="dcon"/>
      
        <XmlDataProvider  x:Key="myXMLdata"  XPath="/Collection/CollectionRecord" IsAsynchronous="False" />

        <Style x:Key="myCheckStyle" TargetType="DataGridCell">
            <!--Setter Property="VerticalAlignment" Value="Center" /-->
            <EventSetter Event="PreviewMouseLeftButtonDown" Handler="DataGridCell_PreviewMouseLeftButtonDown"></EventSetter>
        </Style>
        <Style x:Key="myDataGridRowStyle" TargetType="DataGridRow" >
            
        </Style>


    </Window.Resources>
    <TabControl Name="mainTabControl">
        <TabItem Header="My Collection">
            <DockPanel DataContext="{StaticResource myXMLdata}">
                <StackPanel Name="ButtonsPanel" DockPanel.Dock="Bottom">
                    <StackPanel  Orientation="Horizontal">
                        <Button Width="100" Margin="3" Name="btnScan" Content="Scan dirs" Click="btnScan_Click"></Button>

                        <Button Width="100" Margin="3" Name="btnSave" Content="Save my ratings" Click="btnSave_Click" />
                        <Button Width="100" Margin="3" Name="btnPlayer1" Content="Start player1" Click="btnPlayer1_Click" ToolTip="Create file player1.txt, first line-path to player1.exe, second - player1 name" />
                        <Button Width="100" Margin="3" Name="btnPlayer2" Content="Start player2" Click="btnPlayer2_Click" ToolTip="Create file player2.txt, first line-path to player2.exe, second - player2 name"  />
                        <StackPanel Margin="3">
                            <TextBox Name="filterInput" TextChanged="filterInput_TextChanged" MinWidth="100" BorderBrush="PaleGreen">
                                <TextBox.Background>
                                    <LinearGradientBrush EndPoint="0,1" StartPoint="0.5,0">
                                        <GradientStop Color="White" Offset="0" />
                                        <GradientStop Color="#FF8AFF80" Offset="1" />
                                    </LinearGradientBrush>
                                </TextBox.Background>
                            </TextBox>
                        </StackPanel>
                        <Label Content="{Binding ElementName=dg1, Path=Items.Count}" >
                            <Label.ContentStringFormat>
                                Displayed {0} movies :)
                            </Label.ContentStringFormat>
                        </Label>
                    
                    </StackPanel >
                    <ProgressBar Name="scanProgressBar" Visibility="Collapsed"  Width="{Binding ElementName=Parent,Path=Width}" Height="10" IsIndeterminate="True"></ProgressBar>
                </StackPanel>
                <Grid>
                <DataGrid DockPanel.Dock="Top"   AutoGenerateColumns="False"  ItemsSource="{Binding}" Name="dg1" 
                  RowDetailsVisibilityMode="VisibleWhenSelected" CanUserAddRows="False" Sorting="dg1_Sorting" 
                          RowEditEnding="dg1_RowEditEnding" Loaded="dg1_Loaded" GridLinesVisibility="Horizontal" 
                          IsSynchronizedWithCurrentItem="True" CanUserSortColumns="False" 
                          PreviewMouseLeftButtonUp="dg1_PreviewMouseLeftButtonUp" >
                    <DataGrid.HorizontalGridLinesBrush>
                        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                            <GradientStop Color="Green" Offset="0" />
                            <GradientStop Color="White" Offset="1" />
                        </LinearGradientBrush>
                    </DataGrid.HorizontalGridLinesBrush>
                    <DataGrid.RowStyle>
                        <Style TargetType="DataGridRow">
                            <EventSetter Event="MouseRightButtonUp" Handler="eventDataGridRowMouseRightButtonUp" />
                        </Style>
                    </DataGrid.RowStyle>
                    <DataGrid.Columns>
                        <!--DataGridTextColumn    xml:space="default" x:Name="guidCol" Binding="{Binding XPath=@Shuid}" Header="Shuid" Width="40" IsReadOnly="True"/-->
                        <DataGridTextColumn x:Name="ScanDateTimeColumn" Binding="{Binding XPath=ScanDateTime}" Header="Scan" Width="Auto" IsReadOnly="True"/>
                        <DataGridTextColumn Binding="{Binding XPath=ProductionYear}" Header="Year" Width="SizeToHeader" IsReadOnly="True"></DataGridTextColumn>

                        <!--<DataGridTextColumn   Binding="{Binding XPath=DiskStatus}" Header="On/Off-line" Width="Auto" IsReadOnly="True">
                        </DataGridTextColumn>-->


                        <DataGridTextColumn  x:Name="PathColumn" Binding="{Binding XPath=Path}" Header="Path" Width="Auto" IsReadOnly="True">
                            <DataGridTextColumn.CellStyle>
                                <Style TargetType="{x:Type DataGridCell}">
                                    <Setter Property="Background" Value="{Binding XPath=DiskStatus, Converter={StaticResource StatusColorConv} }" />
                                    <EventSetter Event="DataGridRow.MouseDoubleClick" Handler="dataGridRow_MouseDoubleClick"/>
                                </Style>
                            </DataGridTextColumn.CellStyle>
                        </DataGridTextColumn>

                        <DataGridTextColumn  x:Name="sizeColumn" Binding="{Binding XPath=Size, Converter={StaticResource b2g}}" Header="Size" Width="100" IsReadOnly="True"/>
                        <DataGridTextColumn x:Name="titleColumn" Binding="{Binding XPath=LocalTitle}" Header="Local Title" Width="Auto" MaxWidth="300" IsReadOnly="True">
                            <DataGridTextColumn.CellStyle>
                                <Style TargetType="{x:Type DataGridCell}">
                                    <EventSetter Event="DataGridRow.MouseDoubleClick" Handler="LocalTitle_MouseDoubleClick"/>
                                </Style>
                            </DataGridTextColumn.CellStyle>
                        </DataGridTextColumn>

                        <DataGridTextColumn  Binding="{Binding XPath=Country}" Header="Country" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                        <DataGridTextColumn  Binding="{Binding XPath=OriginalTitle}" Header="Original Title" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                        <DataGridTextColumn  Binding="{Binding XPath=CollectionNumber}" Header="Col №" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                        <DataGridTextColumn  Binding="{Binding XPath=Added}" Header="Added(MM)" Width="Auto" MaxWidth="300" IsReadOnly="True"/>
                        <DataGridTextColumn  Binding="{Binding XPath=RunningTime, Converter={StaticResource runtime}}" Header="Runtime(MM)" Width="SizeToHeader" IsReadOnly="True"/>
                        <DataGridTextColumn  Binding="{Binding XPath=Director}" Header="Director" Width="Auto" MaxWidth="300" IsReadOnly="True"/>

                        <DataGridTemplateColumn Header="MediaInfo"  SortMemberPath="MediaInfo/VideoDetails/@FileType">
                            <DataGridTemplateColumn.CellStyle>
                            <Style TargetType="{x:Type DataGridCell}">
                                <Setter Property="Background" Value="{Binding XPath=DiskStatus, Converter={StaticResource StatusColorConv} }" />
                                    <EventSetter Event="DataGridRow.MouseLeftButtonDown" Handler="MediaInfo_MouseLeftButtonDown"/>
                            </Style>
                            </DataGridTemplateColumn.CellStyle>

                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock><TextBlock.Text>
                                        <MultiBinding StringFormat=" {2} {0}x{1}">
                                            <Binding XPath="MediaInfo/VideoDetails/@Width"></Binding>
                                            <Binding XPath="MediaInfo/VideoDetails/@Height"></Binding>
                                            <Binding XPath="MediaInfo/VideoDetails/@FileType"></Binding>
                                        </MultiBinding>
                                            <!--<Label.ContentStringFormat>
                                        Actor #1 is {0}
                                    </Label.ContentStringFormat>-->
                                </TextBlock.Text></TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <WrapPanel>
                                        <Label Content="{Binding XPath=MediaInfo/VideoDetails/@FileType}">
                                            <Label.ContentStringFormat>FileType: {0}</Label.ContentStringFormat>
                                        </Label>
                                        <Label Content="{Binding XPath=MediaInfo/VideoDetails/@Format}">
                                            <Label.ContentStringFormat>Format: {0}</Label.ContentStringFormat>
                                        </Label>
                                        <Label Content="{Binding XPath=MediaInfo/VideoDetails/@FPS}">
                                            <Label.ContentStringFormat>FPS: {0}</Label.ContentStringFormat>
                                        </Label>
                                        <Label Content="{Binding XPath=MediaInfo/VideoDetails/@Codec}">
                                            <Label.ContentStringFormat>Codec: {0}</Label.ContentStringFormat>
                                        </Label>
                                        <Label Content="{Binding XPath=MediaInfo/VideoDetails/@ScanType}">
                                            <Label.ContentStringFormat>ScanType: {0}</Label.ContentStringFormat>
                                        </Label>
                                        <Label Content="{Binding XPath=MediaInfo/VideoDetails/@AspectRatio}">
                                            <Label.ContentStringFormat>AspectRatio: {0}</Label.ContentStringFormat>
                                        </Label>
                                        <Label Content="{Binding XPath=MediaInfo/VideoDetails/@Width}">
                                            <Label.ContentStringFormat>Width: {0}</Label.ContentStringFormat>
                                        </Label>
                                        <Label Content="{Binding XPath=MediaInfo/VideoDetails/@Height}">
                                            <Label.ContentStringFormat>Height: {0}</Label.ContentStringFormat>
                                        </Label>
                                    </WrapPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>

                        </DataGridTemplateColumn>

                        <DataGridTemplateColumn Header="Artists"  SortMemberPath="Artists/Person/Name">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock>        <TextBlock.Text>
                                        <MultiBinding StringFormat=" {0}, {1}">
                                            <Binding XPath="Artists/Person[1]/Name"></Binding>
                                            <Binding XPath="Artists/Person[2]/Name"></Binding>
                                        </MultiBinding>
                                            <!--<Label.ContentStringFormat>
                                        Actor #1 is {0}
                                    </Label.ContentStringFormat>-->
                                </TextBlock.Text></TextBlock>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <ListBox Height="80" ItemsSource="{Binding XPath=Artists/Person/Name, UpdateSourceTrigger=PropertyChanged}" />
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>

                        </DataGridTemplateColumn>

                        <DataGridTextColumn x:Name="hRezolutionColumn" Binding="{Binding XPath=Ratings/Hrez, Converter={StaticResource s2i}}" 
                                    Header="Horiz.Rezol" Width="Auto" SortMemberPath="Ratings/Hrez"/>
                        <DataGridTemplateColumn x:Name="userRateColumn" Header="User Rate" Width="Auto" SortMemberPath="Ratings/UserRate">
                            <DataGridTemplateColumn.CellStyle>
                                <Style TargetType="{x:Type DataGridCell}">
                                    <Setter Property="Background" Value="{Binding XPath=Ratings/UserRate, Converter={StaticResource dcon} }" />
                                </Style>
                            </DataGridTemplateColumn.CellStyle>

                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Label Content="{Binding Path=Value,ElementName=sl0}"/>
                                        <Slider Name="sl0" MinWidth="50" Maximum="5" Value="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, XPath=Ratings/UserRate}" 
                                        SmallChange="1" TickPlacement="BottomRight" IsSnapToTickEnabled="True" />
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Label Content="{Binding XPath=Ratings/UserRate}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

                        <DataGridTemplateColumn x:Name="soundRateColumn" Header="Sound Rate" Width="Auto" SortMemberPath="Ratings/SoundRate">
                            <DataGridTemplateColumn.CellStyle>
                                <Style TargetType="{x:Type DataGridCell}">
                                    <Setter Property="Background" Value="{Binding XPath=Ratings/SoundRate, Converter={StaticResource dcon} }" />
                                </Style>
                            </DataGridTemplateColumn.CellStyle>

                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Label Content="{Binding Path=Value,ElementName=sl1}"/>
                                        <Slider Name="sl1" MinWidth="50" Maximum="5" Value="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, XPath=Ratings/SoundRate}" SmallChange="1" TickPlacement="BottomRight" IsSnapToTickEnabled="True" />
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Label Content="{Binding XPath=Ratings/SoundRate}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

                        <DataGridTemplateColumn x:Name="pictureRateColumn" Header="Picture Rate" Width="SizeToHeader" SortMemberPath="Ratings/PicRate">
                            <DataGridTemplateColumn.CellStyle>
                                <Style TargetType="{x:Type DataGridCell}">
                                    <Setter Property="Background" Value="{Binding XPath=Ratings/PicRate, Converter={StaticResource dcon} }" />
                                </Style>
                            </DataGridTemplateColumn.CellStyle>

                            <DataGridTemplateColumn.CellEditingTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Label Content="{Binding Path=Value,ElementName=sl2}"/>
                                        <Slider Name="sl2" MinWidth="50" Maximum="5" Value="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, XPath=Ratings/PicRate}" SmallChange="1" TickPlacement="BottomRight" IsSnapToTickEnabled="True" />
                                    </StackPanel>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate >
                                    <Label Content="{Binding XPath=Ratings/PicRate}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

                        <DataGridTemplateColumn  SortMemberPath="Ratings/OrigSound" Header="Snd" CellStyle="{StaticResource myCheckStyle}">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox 
                                        IsChecked="{Binding XPath=Ratings/OrigSound, 
                                        Converter={StaticResource int2check},UpdateSourceTrigger=LostFocus,NotifyOnTargetUpdated=True}" 
                                              IsThreeState="True"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>


                        <DataGridTemplateColumn SortMemberPath="Ratings/OrigSub" Header="Sub" CellStyle="{StaticResource myCheckStyle}">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox 
                                        IsChecked="{Binding XPath=Ratings/OrigSub, 
                                        Converter={StaticResource int2check},UpdateSourceTrigger=LostFocus,NotifyOnTargetUpdated=True}" 
                                              IsThreeState="True" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

                        
                        <DataGridTextColumn Binding="{Binding XPath=OperationComment}" Header="Operation comment"/>
                    </DataGrid.Columns>
                </DataGrid>
                </Grid>
            </DockPanel>
        </TabItem>
        <TabItem Header="Setup">
            <StackPanel >
                <StackPanel Orientation="Horizontal">
                    <TextBox Name="newItemNextBox" MinWidth="200">enter path here</TextBox>
                    <Button Name="btnAddNewPath" Click="btnAddNewPath_Click">Add to scan list</Button>
                </StackPanel>
                <Label>Directory list for Scan</Label>
                <ListBox SelectionMode="Multiple" Name="scanListBox" MinHeight="100" MaxHeight="300" SnapsToDevicePixels="True"></ListBox>
                <StackPanel Orientation="Horizontal">
                    <Button Click="Button_Click">Delete selected</Button>
                    <Button Name="dirlistsaveButton" Click="dirlistsaveButton_Click">Save this list</Button>
                </StackPanel>
            </StackPanel>
        </TabItem>
        <TabItem Header="Diagnostic Messages">
            <StackPanel >
                <ListBox Name="logListBox" Height="300"></ListBox>
                <Button Content="ClearLog" Name="btnClearLog" Click="btnClearLog_Click" />
            </StackPanel>
        </TabItem>
        <TabItem Header="About">
            <TextBlock Margin="20">
                ShumaDaf - movies collection managment program.<LineBreak />
                This program is Freeware. <LineBreak/>Source code absolutly free available at our home page<LineBreak></LineBreak>
                Project Home is <Bold>http://shumadaf.codeplex.com </Bold> (thanks to Microsoft for free hosting).<LineBreak />
                Visit out Home page for check new releases and read site documentation for search answers on any questions.<LineBreak />
                Developers Team: Valery Sherbanov <Bold>sherbanov@hotmail.com</Bold>  and SullenBear (realy sullen ;) ) .<LineBreak></LineBreak>
                - No ads, no eggs!
            </TextBlock>
        </TabItem>
    </TabControl>
</Window>
